﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Softserve.NumberToWords.Abstract;

namespace Softserve.NumberToWords.Concrete
{
    class DeutschDictionary : ConvertDictionaryBase
    {
        #region Const
        private const string generalTemplate = "";
        private const string teenTemplate = "{0}{1}";
        private const string DecimalTemplate = "{1}und{0}";
        public readonly Dictionary<int, string> ExceptionNumbers = default(Dictionary<int, string>); 
        #endregion

        #region Ctor
        public DeutschDictionary()
        {
            FirstNumbers = new List<string>() { "null", "ein", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf", "zwölf" }; ;
            Teen = new List<string>() { "zehn", "hundert", "tausend", "million", "billion" };
            DecimalNumbers = new List<string>() { "zwanzig", "dreißig", "vierzig", "fünfzig", "sechzig", "siebzig", "achtzig", "neunzig" };
            TeenNumbersCount = (byte)(19 - FirstNumbers.Count);
            ExceptionNumbers = new Dictionary<int, string>();
            GeneralTemplate = generalTemplate;
        } 
        #endregion

        #region ConvertBase Implementation
        public override string GetDecimalNumber(int number)
        {
            byte dec = (byte)(number / 10);
            if (number > 19 && number % 10 > 0)
            {
                string s = string.Format(DecimalTemplate, DecimalNumbers[dec - 2], FirstNumbers[number - dec * 10]);
                return s;
            }
            else
            {
                return DecimalNumbers[dec - 2];
            }
        }


        public override string GetTeenNumber(int number)
        {
            if (number < 20 && !ExceptionNumbers.ContainsKey(number))
            {
                if (number < 14)
                {
                    return FirstNumbers[number];
                }
                else
                {
                    return string.Format(teenTemplate, FirstNumbers[number - 10], Teen[0]);
                }
            }
            if (ExceptionNumbers.ContainsKey(number))
            {
                return ExceptionNumbers[number];
            }
            return null;
        } 
        #endregion
    }
}
